# pub/counter_pub.py

import rclpy
from rclpy.node import Node
from std_msgs.msg import String
from datetime import datetime

class CounterPublisher(Node):
    def __init__(self):
        super().__init__('counter_pub')
        self.publisher_ = self.create_publisher(String, 'counter_info', 10)
        self.timer = self.create_timer(1.0, self.timer_callback)
        self.counter = 0

    def timer_callback(self):
        msg = String()
        msg.data = f'Count: {self.counter}, Time: {datetime.now()}'
        self.publisher_.publish(msg)
        self.counter = (self.counter + 1) % 101

def main(args=None):
    rclpy.init(args=args)
    counter_publisher = CounterPublisher()
    rclpy.spin(counter_publisher)
    counter_publisher.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()
